﻿<controls:MetroWindow x:Class="Papercut.Views.MainView"
                      xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                      xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
                      xmlns:model="clr-namespace:Papercut.ViewModels"
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                      xmlns:ViewModels="clr-namespace:Papercut.ViewModels"
                      xmlns:cal="http://www.caliburnproject.org"
                      xmlns:Behaviors="clr-namespace:Papercut.Behaviors"
                      xmlns:MahAppsBehaviors="http://metro.mahapps.com/winfx/xaml/shared"
                      xmlns:Wpf="clr-namespace:TheArtOfDev.HtmlRenderer.WPF;assembly=HtmlRenderer.WPF"
                      mc:Ignorable="d"
                      d:DataContext="{x:Type ViewModels:MainViewModel}"
                      ResizeMode="CanResizeWithGrip"
                      Height="{Behaviors:SettingBinding Window_Height}" Width="{Behaviors:SettingBinding Window_Width}"
                      Icon="/Papercut;component/App.ico"
                      VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                      Title="{Binding WindowTitle}" Background="White"
                      BorderThickness="{DynamicResource AccentBorderThickness}" 
                      GlowBrush="{DynamicResource AccentGlowBrush}"
                      BorderBrush="{DynamicResource AccentBorderBrush}">
    <controls:MetroWindow.RightWindowCommands>
        <controls:WindowCommands>
            <Button ToolTip="View Log"
                    cal:Message.Attach="[Event Click] = [Action ToggleLog]">
                <StackPanel Orientation="Horizontal">
                    <Rectangle Width="20" Height="20"
                               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                        <Rectangle.OpacityMask>
                            <VisualBrush Stretch="Fill"
                                         Visual="{StaticResource appbar_console}" />
                        </Rectangle.OpacityMask>
                    </Rectangle>
                    <TextBlock Margin="4 0 0 0"
                               VerticalAlignment="Center"
                               Text="Log" />
                </StackPanel>
            </Button>
            <Button ToolTip="Configure Automatic Rules"
                    cal:Message.Attach="[Event Click] = [Action ShowRulesConfiguration]">
                <StackPanel Orientation="Horizontal">
                    <Rectangle Width="20" Height="20"
                               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                        <Rectangle.OpacityMask>
                            <VisualBrush Stretch="Fill"
                                         Visual="{StaticResource appbar_layer}" />
                        </Rectangle.OpacityMask>
                    </Rectangle>
                    <TextBlock Margin="4 0 0 0"
                               VerticalAlignment="Center"
                               Text="Rules" />
                </StackPanel>                
            </Button>
            <Button ToolTip="Configure Papercut Options" cal:Message.Attach="[Event Click] = [Action ShowOptions]">
                <StackPanel Orientation="Horizontal">
                    <Rectangle Width="20" Height="20"
                               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                        <Rectangle.OpacityMask>
                            <VisualBrush Stretch="Fill"
                                         Visual="{StaticResource appbar_settings}" />
                        </Rectangle.OpacityMask>
                    </Rectangle>
                    <TextBlock Margin="4 0 0 0"
                               VerticalAlignment="Center"
                               Text="Options" />
                </StackPanel>
            </Button>
            <Button ToolTip="Shut Down Papercut App" cal:Message.Attach="[Event Click] = [Action Exit]">
                <StackPanel Orientation="Horizontal">
                    <Rectangle Width="20" Height="20"
                               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                        <Rectangle.OpacityMask>
                            <VisualBrush Stretch="Fill"
                                         Visual="{StaticResource appbar_power}" />
                        </Rectangle.OpacityMask>
                    </Rectangle>
                    <TextBlock Margin="4 0 0 0"
                               VerticalAlignment="Center"
                               Text="Exit" />
                </StackPanel>
            </Button>
        </controls:WindowCommands>
    </controls:MetroWindow.RightWindowCommands>

    <controls:MetroWindow.Flyouts>
        <controls:FlyoutsControl>
            <controls:Flyout Header="Log" IsOpen="{Binding IsLogOpen}" Name="LogFlyout" Position="Bottom">
                <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto">
                    <Wpf:HtmlPanel x:Name="LogPanel" MaxHeight="300" Background="#282828" />    
                </StackPanel>
            </controls:Flyout>
        </controls:FlyoutsControl>
    </controls:MetroWindow.Flyouts>

    <Grid IsSharedSizeScope="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="Auto"
          ShowGridLines="False" Width="Auto">
        <Grid x:Name="Overlay" Panel.ZIndex="1000"
              Visibility="{Binding IsDeactivated,Converter={StaticResource CollapsedIfFalse}}">
            <Grid.Background>
                <SolidColorBrush Color="White" Opacity=".25" />
            </Grid.Background>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="325*" />
                <RowDefinition Height="47" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="160" Width="150*" />
                <ColumnDefinition Width="3" />
                <ColumnDefinition Width="500*" />
            </Grid.ColumnDefinitions>
            <ContentControl Grid.Column="0" x:Name="MessageListViewModel" VerticalAlignment="Stretch"
                            HorizontalAlignment="Stretch" />
            <GridSplitter
                ResizeDirection="Columns"
                Grid.Column="1"
                Grid.Row="0"
                Width="3"
                Height="Auto"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Margin="0" />

            <ContentControl Grid.Column="2" Grid.Row="0" x:Name="MessageDetailViewModel" VerticalAlignment="Stretch"
                            HorizontalAlignment="Stretch"
                            IsEnabled="{Binding Path=MessageListViewModel.HasSelectedMessage}" />

            <Button Height="28" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="4,0,0,9" Width="72"
                    Name="ForwardSelected" IsEnabled="{Binding Path=MessageListViewModel.HasSelectedMessage}"
                    Grid.Row="1">
                Forward
            </Button>

            <Button Height="28" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="81,0,0,9" Width="72"
                    Name="DeleteSelected" IsEnabled="{Binding Path=MessageListViewModel.HasSelectedMessage}"
                    Content="{Binding Path=MessageListViewModel.DeleteText}"
                    cal:Bind.ModelWithoutContext="{Binding Path=MessageListViewModel}"
                    cal:Message.Attach="[Event Click] = [Action DeleteSelected]" Grid.Row="1" />

            <Image Height="42" Margin="6,0,0,3" Name="image1" Stretch="Fill" VerticalAlignment="Bottom"
                   HorizontalAlignment="Left" Width="42" Source="/Papercut;component/App.ico" Grid.Row="1"
                   Grid.Column="2" />

            <Label Margin="52,0,0,13" Name="versionLabel" VerticalAlignment="Bottom" FontSize="10" Foreground="#696969"
                   Grid.Column="2" Grid.Row="1" HorizontalAlignment="Left" Width="132" Content="{Binding Version}" />

            <Label Margin="53,0,0,2" VerticalAlignment="Bottom" FontSize="9" Foreground="#2e74a6" Cursor="Hand"
                   ToolTip="Click to visit the site" Grid.Column="2" Grid.Row="1"
                   Content="https://papercut.codeplex.com"
                   HorizontalAlignment="Left" cal:Message.Attach="[Event MouseUp] = [Action GoToSite]" />
        </Grid>
    </Grid>
</controls:MetroWindow>